<?php
/**
 * Created by PhpStorm.
 * User: 跳梁
 * Date: 2015/10/29
 * Time: 15:19
 */
class AlipayBackAction extends Action{
    public function callback(){
        echo "success";
        $sn =  $_POST['out_trade_no'];
        $transactionId = $_POST['trade_no'];
        $appid = $_POST['app_id'];
        $status = $_POST['trade_status'];
        Session::switchCustomer(0);
        if($status=='TRADE_SUCCESS'){
            $alipaySetting = D("customer_mall_alipay_setting");
            $orderModel = M("module_product_order");
            $alipayInfo = $alipaySetting->where("appId='$appid'")->find();
            $cid = $alipayInfo['customerId'];
            Session::switchCustomer($cid);
            $whereOrderSn["tempSerialNumber"] = $sn;
            $status = $orderModel->where($whereOrderSn)->getField("status");
            if($status!=order_status_refund){
                $oidArr = $orderModel->where($whereOrderSn)->getField('id' ,true);
                $oid = implode(",", $oidArr);
                R('Product/deductProductInventory', array($oid));
                $result = ProductOrder::updateOrderDone($cid, $oid, $transactionId, true);
            }
        }
        return "success";
    }
}